var navSwiper;
var goodlistSwiper;
$(function(){ 
	var containerSwiper=new Swiper('.container',{
		onSlideChangeStart:function(swiper){
//			console.log(swiper.activeIndex);
			navSwiper.slideTo(swiper.activeIndex,200);
			$("nav li").removeClass("active").eq(swiper.activeIndex).addClass("active");
		}
	})
	
//	获取商品分类
	var baseurl2="http://datainfo.duapp.com/shopdata/getclass.php"
	$.ajax({
		type:"get",
		url:baseurl2,
		success:function(data){
//			console.log(data);
			$(".navul").html('');
			var navul="";
			var str=JSON.parse(data);
			for(var i=0;i<str.length;i++){
				navul+="<li class='swiper-slide'><i class='iconfont'>"+str[i].icon+"</i></li>"
			}
			$(".navul").append(navul);
			navSwiper=new Swiper('.navlist',{
				slidesPerView : 5,
				onTap:function(swiper,event){
				f1(swiper.clickedIndex+1);
				containerSwiper.slideTo(swiper.clickedIndex,200);
				$("nav li").removeClass("active").eq(swiper.clickedIndex).addClass("active");
				}
			})
		}
	});
	
	function f1(classID){
		var baseurl2="http://datainfo.duapp.com/shopdata/getGoods.php"
		console.log(classID);
		$.ajax({
			type:"get",
			url:baseurl2,
			dataType:"jsonp",
			data:"classID="+classID,
			success:function(data){
				$(".goodlist .swiper-wrapper").html('');
//				console.log(data);
				var goods="";
				for(var k=0;k<data.length;k++){
					goods+="<div class='swiper-slide slides'><div class='newgood1' goodsID='"+data[k].goodsID+"'><a href='detaild.html'><img src='"+
					data[k].goodsListImg+"'/></a><p>"+
					data[k].goodsName+"</p><b>￥"+
					data[k].price+"</b><span>￥999</span></div></div>"
				}
				$(".goodlist .swiper-wrapper").append(goods);
				goodlistSwiper=new Swiper('.goodlist',{
					direction:"vertical",
					slidesPerView:'auto',
				})
				$('.newgood1 img').click(function(){
					var goodsID=$(this).parents('.newgood1').attr('goodsID');
					localStorage.setItem('goodsID',goodsID);
					window.location.href="detaild.html";
				})
			}
		});
	}f1(1)	
})
